package com.bs.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bs.model.User;
import com.bs.service.IUserService;
import com.bs.vo.RestResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 说明：
 *
 * @author 琪
 * @since 2025/5/7 20:29
 */
@RestController
@RequestMapping("user")
@Api(tags = "用户接口")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("add")
    @ApiOperation(value = "添加用户")
    public RestResultVo<User> addUser(@RequestBody User user) {
        userService.save(user);
        return RestResultVo.ok(user);
    }

    @GetMapping("delete")
    @ApiOperation(value = "删除用户")
    public RestResultVo<Boolean> deleteUser(String id) {
        userService.removeById(id);
        return RestResultVo.success();
    }

    @PostMapping("update")
    @ApiOperation(value = "修改用户")
    public RestResultVo<User> updateUser(@RequestBody User user) {
        userService.updateById(user);
        return RestResultVo.ok(user);
    }

    @GetMapping("query")
    @ApiOperation(value = "查询用户")
    public RestResultVo<User> queryUser(String id) {
        User user = userService.getById(id);
        return RestResultVo.ok(user);
    }

    @PostMapping("list")
    @ApiOperation(value = "查询用户列表")
    public RestResultVo<List<User>> listUser(@RequestBody User user) {
        List<User> list = userService.list(new QueryWrapper<>(user));
        return RestResultVo.ok(list);
    }

}
